package AddProduct;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

 /**
  * This class is used by servlets to get database connection and also get some data from database.
  * @author desso_000
  *
  */
public class SQL {
	
	private static final String USERNAME = "store";
	private static final String PASSWORD = "store";

   /*
    * get database connection
    */
	public static Connection getConnection() throws ClassNotFoundException, SQLException {
		Class.forName("oracle.jdbc.OracleDriver");
		return DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/xe", USERNAME, PASSWORD);
	}
	
	/*
	 * get some data based on query that you insert
	 */
   public static ResultSet getDataFromDatabase(Connection dbConnection, String query) throws SQLException, ClassNotFoundException {
		PreparedStatement prepareStatement = dbConnection.prepareStatement(query);
		return prepareStatement.executeQuery();
	}
   
    static String getUsername() {
		return USERNAME;
	}

	static String getPassword() {
		return PASSWORD;
	}

}
